<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>首页</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>

<div class="layui-carousel" id="test1">
    <div carousel-item>
        <div><img src="/images/1.jpg" style="width: 100%; height: 100%;object-fit: cover"></div>
        <div><img src="/images/2.jpg" style="width: 100%; height: 100%;object-fit: cover"></div>
        <div><img src="/images/3.jpg" style="width: 100%; height: 100%;object-fit: cover"></div>
        <div><img src="/images/4.jpg" style="width: 100%; height: 100%;object-fit: cover"></div>
    </div>
</div>
<!-- 条目中可以是任意内容，如：<img src=""> -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>公告</legend>
</fieldset>
<div class="layui-collapse" lay-accordion="">

</div>
<script src="/layui/layui.js"></script>
<script>
    layui.use(['carousel','jquery','layer','form','element'] ,function(){
        var carousel = layui.carousel;
        var form=layui.form;
        var $=layui.jquery;
        var layer=layui.layer;
        var element=layui.element;
        //建造实例
        carousel.render({
            elem: '#test1'
            ,width: '100%' //设置容器宽度
            ,height:'200'
            ,arrow: 'always' //始终显示箭头
            ,autoplay:true
            //,anim: 'updown' //切换动画方式
        });
        $.get('/api/announcement',function (res) {
            var html='';
            $.each(res.data,function (i,obj) {
                html +='<div class="layui-colla-item"><h2 class="layui-colla-title">'+obj.title+'<i class="layui-icon layui-colla-icon"></i></h2> <div class="layui-colla-content layui-show"><p>'+obj.contents+'</p></div></div>';
            })
            $('.layui-collapse').html(html);

            element.render();
        })
        element.on('collapse(test1)',function (data) {
            layer.msg('展开状态:'+data.show);
        })
    });
</script>
</body>
</html>